package com.lhy.tool.database.converter.db2;

import com.lhy.tool.database.DbColumnType;
import com.lhy.tool.database.converter.common.AbstractDbColumnTypeMapping;
import com.lhy.tool.database.converter.ColumnTypeMappingRule;
import org.springframework.stereotype.Component;

public class DB2ColumnTypeMapping extends AbstractDbColumnTypeMapping {

    public DB2ColumnTypeMapping() {
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("char") || columnType.contains("text")
                || columnType.contains("json") || columnType.contains("enum"), (columnType) -> DbColumnType.STRING));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("bigint"), (columnType) -> DbColumnType.LONG));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("smallint"), (columnType) -> DbColumnType.BASE_SHORT));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("int"), (columnType) -> DbColumnType.INTEGER));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("bit"), (columnType) -> DbColumnType.BOOLEAN));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("decimal"), (columnType) -> DbColumnType.BIG_DECIMAL));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("datetime") || columnType.contains("time")
                || columnType.contains("year") || columnType.contains("timestamp"), (columnType) -> DbColumnType.DATE));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("clob"), (columnType) -> DbColumnType.CLOB));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("blob"), (columnType) -> DbColumnType.BLOB));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("binary"), (columnType) -> DbColumnType.BYTE_ARRAY));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("float"), (columnType) -> DbColumnType.FLOAT));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("double"), (columnType) -> DbColumnType.DOUBLE));
    }

}
